package com.sdwulongshan.deregister;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import top.wuyouteam.register.Register;

public class MainActivity extends Activity {
   // 声明控件
    private  static EditText IdEdit;
    private  static Button copycode;
    // 这是注册机内定义的加数，可自定义
    private  static final  String CONF = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#1234567899876543210...@@@";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 初始化
        INIT();
        copycode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取用户输入的值
                String androidId = IdEdit.getText().toString();
                // 判断该值是否为null或空串
                if ("".equals(androidId)|| androidId == null){
                    Toast.makeText(getApplicationContext(),"您好像还没有输入内容！",Toast.LENGTH_LONG).show();
                } else {
                  // 生成注册码
                   String registercode =   Register.createRegisterCode(androidId,CONF);
                    // 将结果copy到粘贴板
                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setText(registercode);
                    Toast.makeText(getApplicationContext(),"注册码已复制！",Toast.LENGTH_LONG).show();
                }

            }
        });
    }

    // 初始化方法

    private  void  INIT() {
        IdEdit = findViewById(R.id.IdEdit);
        copycode = findViewById(R.id.copycode);
    }
}